home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / flight / flight.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  12.4 KB  |  481 lines

  1. /*
  2.  * Copyright 1984-1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /*
  19.  *  flight/flight.h $Revision: 1.31 $
  20.  */
  21.  
  22. #ifndef __FLIGHT_H__
  23. #define __FLIGHT_H__
  24.  
  25. #include <gl.h>
  26. #include <device.h>
  27. #include <math.h>
  28. #include <stdio.h>
  29.  
  30. #include "gobj.h"
  31. #include "colors.h"
  32. #include "objects.h"
  33. #include "collision.h"
  34. #include "Xzmsg.h"
  35.  
  36. #ifdef AUDIO
  37. #include "sound.h"
  38. #endif
  39.  
  40. /* order of gobj.h and colors.h is important */
  41.  
  42. /* Color map thing */
  43. #define DEFAULT_BIT_CMODE 4
  44.  
  45. #define DATADIR "/usr/demos/data/flight/"
  46.  
  47. #define START_X 850.0
  48. #define START_Y 0.0
  49. #define START_Z -2050.0
  50. #define START_AZIMUTH 900
  51.  
  52. #define HEADER_VERSION HEADER(3.4)
  53. #define VERSION_NUMBER 3.4
  54.  
  55. #ifndef NULL
  56. #define NULL 0
  57. #endif
  58.  
  59. #define IN_BOX(p, llx, urx, llz, urz) \
  60.     (llx <= p->x && p->x <= urx && llz <= p->z && p->z <= urz)
  61.  
  62. #define DOT(A, B) (A[0]*B[0] + A[1]*B[1] + A[2]*B[2])
  63.  
  64. extern int xasin();
  65.  
  66. #define MAX_PLANES 16
  67. #define NAME_LENGTH 15
  68.  
  69. struct plane {
  70.     long planeid;
  71.  
  72.     char  version;        /* flight version    */
  73.     char  cmd;            /* type of packet    */
  74.     short type;            /* plane type        */
  75.     short alive;        /* is this plane still sending packets */
  76.     char  myname[NAME_LENGTH+1];
  77.  
  78.     unsigned short status;
  79.     unsigned short won;        /* for msgs these 2 shorts */
  80.     unsigned short lost;    /* hold the plane id    */
  81.  
  82.     float x;            /* plane position    */
  83.     float y;            /* in feet        */
  84.     float z;
  85.     short azimuth;        /* in 10th of degrees    */
  86.     short elevation;
  87.     short twist;
  88.  
  89.     short mstatus;        /* missile data        */
  90.     float mx;
  91.     float my;
  92.     float mz;
  93.     float last_mx;
  94.     float last_my;
  95.     float last_mz;
  96.     long mkill;
  97.     float tps;            /* ticks per second    */
  98.     int airspeed;        /* air speed in knots    */
  99.     int thrust;            /* 0-100 percent    */
  100.     short wheels;        /* wheel position    */
  101.     short elevator;        /* elevator position    */
  102.     char mtype;            /* missile type        */
  103.     unsigned char weapon_state;    /* weapon state bits    */
  104.     short rollers;        /* rollers position    */
  105. };
  106.  
  107.  
  108. #define RADAR_HISTORY 16*20
  109.  
  110. typedef struct {
  111.     long id;
  112.     int n;
  113.     int velocity;        /* overall velocity        */
  114.     float vx, vy, vz;        /* plane velocity in user space    */
  115.     char buf[80];        /* text buffer            */
  116.     int status[RADAR_HISTORY];
  117.     float x[RADAR_HISTORY];
  118.     float y[RADAR_HISTORY];
  119.     float z[RADAR_HISTORY];
  120. } radar_hist_t;
  121.  
  122. extern radar_hist_t radar_history[];
  123.  
  124. #define NUM_BUILDINGS 5
  125.  
  126. #define MAX_OBJS    20    /* maximum number of objects */
  127. /*
  128.  *  object types
  129.  */
  130. #define BUILDING_OBJ    0
  131. #define THREAT_OBJ    1
  132. #define HILL_OBJ    2
  133. #define PLANE_OBJ    3
  134. #define MISSILE_OBJ    4
  135.  
  136. typedef struct {
  137.     int type;
  138.     float cx;
  139.     float cy;
  140.     float cz;
  141.     int mode;
  142.     int id;
  143.     object_t *obj;
  144. } obj_list_t;
  145.  
  146. extern obj_list_t sort_obj[MAX_OBJS];
  147. extern obj_list_t sort_plane[MAX_PLANES];
  148. extern obj_list_t sort_missile[MAX_PLANES];
  149. extern int obj_count;
  150.  
  151.  
  152. typedef struct plane *Plane;
  153. extern Plane planes[], get_indata(), lookup_plane(), find_closest_plane();
  154. extern Plane plane_futures[];
  155. extern Plane *find_plane();
  156. extern int number_planes;    /* number of planes in game */
  157.  
  158.  
  159. #define DATA_PACKET 0
  160. #define MSG_PACKET 1
  161. #define SUPERKILL_PACKET 2
  162. #define KILL_PACKET 23
  163.  
  164.  
  165. /*
  166.  *  plane history data
  167.  */
  168. #define MT_MAX    30
  169. struct plane_hist {
  170.     int malive;
  171.     float mt[MT_MAX][3];        /* missile track */
  172.     int mtpos, mtspos, mtlen;
  173. };
  174.  
  175. typedef struct plane_hist *Plane_hist;
  176. extern Plane_hist plane_hists[];
  177.  
  178. /*
  179.  *  macros for accessing plane data
  180.  */
  181. #define FOR_EACH_MSG(p,pp) \
  182.     for (pp = messages, p = *pp++; p->alive > 0; p = *pp++)
  183.  
  184. #define FOR_EACH_PLANE(p,pp) \
  185.     for (pp = planes, p = *pp++; p->alive > 0; p = *pp++)
  186.  
  187. #define FOR_EACH_PLANE_I(i, p) \
  188.     for (i = !shadow, p = planes[i]; p->alive > 0; p = planes[++i])
  189.  
  190. #define FOR_EACH_PLANE_AND_FUTURE(p,pp,pf,ppf) \
  191.     for (pp = (shadow)? planes : &planes[1], p = *pp++, \
  192.          ppf = (shadow)? plane_futures : &plane_futures[1], pf = *ppf++; \
  193.          p->alive > 0; p = *pp++, pf = *ppf++)
  194.  
  195. #define FOR_EACH_PLANE_AND_HIST(p,pp,ph,pph) \
  196.     for (pp = planes, p = *pp++, pph = plane_hists, ph = *pph++; \
  197.          p->alive > 0; p = *pp++, ph = *pph++)
  198.  
  199. #define PLANE_ID(p) ((p)->planeid)
  200. #define NULL_PLANE_ID -1
  201.  
  202.  
  203. /*
  204.  *  weapon types
  205.  */
  206. #define TYPE_ROCKET 0
  207. #define TYPE_SIDEWINDER 1
  208. #define TYPE_CANNON 2
  209. #define TYPE_SAM 3
  210.  
  211. /*
  212.  *  patterns
  213.  */
  214. #define CRASH_PATTERN 1
  215. #define SHADOW_PATTERN 2
  216. #define EXPL_PAT0 80
  217.  
  218. #define TPS tps
  219. /*#define TPS 20*/
  220. #define G_ACC 32.0
  221. /*#define GRAVITY (G_ACC/TPS/TPS)*/
  222. #define GRAVITY gravity
  223.  
  224. /*
  225.  *  plane status
  226.  */
  227. /* hard code it to 20 to be compatable with GL1 versions
  228. #define MEXPLODE (2 * TPS)    */
  229. #define MEXPLODE 20
  230. #define MFINISH (MEXPLODE + 1)
  231. #define MLIFE (10 * int_tps)
  232. #define MSTART (MFINISH + MLIFE)
  233.  
  234. /*
  235.  *  some meter screen coordinates
  236.  */
  237. #define METER_VLLX 62
  238. #define METER_VURX 1225
  239. #define METER_VLLY 133
  240. #define METER_VURY 400
  241. #define THRUST_LLX 62
  242. #define SPEED_LLX (THRUST_LLX*3)
  243. #define CLIMB_LLX (THRUST_LLX*5)
  244. #define HEADING_CX 937
  245. #define FUEL_LLX 1163
  246. #define HUD_MARGIN 250
  247.  
  248. /*
  249.  *  timing info
  250.  */
  251. extern int int_tps;                /* integer ticks per second */
  252. extern float tps;                /* ticks per second */
  253. extern short tick_counter;            /* counts the loop ticks */
  254. extern struct tms tms_start_buf, tms_end_buf;    /* timer buffer */
  255. extern int time_start, time_end;        /* start/end times */
  256.  
  257. /*
  258.  *  screen and window info
  259.  */
  260. extern int xorigin, yorigin;
  261. extern int xmaxscreen, ymaxscreen;
  262. extern int xmaxwindow, ymaxwindow;
  263. extern int xmiddle, ymiddle;
  264. extern int zminscreen, zmaxscreen;
  265. extern int inst_x1, inst_x2, inst_y1, inst_y2;
  266. extern int report_x1, report_x2, report_y1, report_y2;
  267.  
  268. /*
  269.  *  display state info
  270.  */
  271. extern int plate_ci_mode;
  272. extern int in_cmode;
  273. extern int force_cmode;
  274. extern int force_rgb;
  275. extern int bits_cmode;
  276. extern int bits_over;
  277. extern int bits_under;
  278. extern long over_drawmode;    /* OVERDRAW or PUPDRAW */
  279. extern int ms_samples;
  280.  
  281.  
  282. /*
  283.  *  mouse and spaceball positions
  284.  */
  285. extern long mousex, mousey, sbtx, sbtz;
  286.  
  287. extern char status_text[60];
  288.  
  289. extern float gravity;
  290.  
  291. extern int ftime;        /* time of day in flight in minutes */
  292.  
  293. extern float sunx, suny, sunz;    /* position of sun */
  294. extern int lightson;
  295.  
  296. extern int fogon;
  297. extern int texon;
  298.  
  299. extern Matrix identmat;
  300.  
  301. extern int restart;
  302.  
  303. /*
  304.  *  flags
  305.  */
  306. extern short debug;            /* TRUE if in debug mode */
  307. extern short dogfight;            /* TRUE if dogfight */
  308. extern short shadow;            /* TRUE if shadow */
  309. extern short radar;            /* TRUE if radar */
  310. extern short hud;            /* TRUE if hud, else meters */
  311. extern short threat_mode;        /* TRUE if threats envelopes */
  312. extern short timeit;            /* TRUE if displaying timing info */
  313. extern short test_mode;            /* test mode uses no fuel */
  314. extern short dials;            /* TRUE if using dials */
  315. extern short new_inst;            /* TRUE if using new instroments */
  316. extern short show_help;            /* TRUE if displaying help */
  317.  
  318.  
  319. /*
  320.  *  geomety objects
  321.  */
  322. extern object_t *runwayobj;
  323. extern object_t *lightsobj;
  324. extern object_t *hillsobj;
  325. extern object_t *mtnsobj;
  326. extern object_t *buildingsobj;
  327. extern object_t *planeobj[9];
  328. extern object_t *swobj;
  329. extern object_t *threatobj;
  330. extern object_t *planeboxobj;
  331. extern char datadir[];
  332. extern char sounddir[];
  333. extern char objdir[];
  334. extern char objfname[];
  335. extern grid_t *hillsgrid;
  336.  
  337.  
  338. /*
  339.  *  plane design parameters
  340.  */
  341. extern char *plane_type;        /* plane type (i.e. "F-15") */
  342. extern float s;                /* wing area in sq. feet */
  343. extern float W;                /* weight of plane in lbs. */
  344. extern float fuel_weight;        /* weight of fuel */
  345. extern float Mthrust;            /* maximum thrust */
  346. extern float b;                /* wing span in feet */
  347. extern float ef;            /* efficiency factor */
  348. extern float Fmax;            /* maximum flap deflection */
  349. extern float Smax;            /* maximum spoiler deflection */
  350. extern float ELEVF;            /* elevator rate in degrees/sec */
  351. extern float ROLLF;            /* roll rate (both at 300 mph) */
  352. extern float pilot_eye[4];        /* pilots eye position */
  353. extern float Lmax;            /* maximum lift before wing breaks */
  354. extern float Lmin;            /* minimum lift before wing breaks */
  355. extern float plane_height;        /* height of plane midpoint */
  356. extern int MAX_RK, MAX_SW;        /* max rockets and sidewinders */
  357. extern int MIN_LIFT_SPEED;        /* minimum lift-up speed fps */
  358.  
  359. /*
  360.  *  computed plane design parameters
  361.  */
  362. extern float gefy;            /* maximum height for ground effect */
  363. extern float fuel_rate;            /* fuel consumption rate */
  364. extern float ipi_AR;            /* 1.0 / pi * wing Aspect Ratio */
  365. extern float ie_pi_AR;            /* 1.0 / pi * AR * efficiency */
  366.  
  367. /*
  368.  *  variable plane design parameters
  369.  */
  370. extern float inverse_mass;        /* 1.0 / mass of plane */
  371. extern float Lmax_g;            /* Lmax * gravity */
  372. extern float Lmin_g;            /* Lmin * gravity */
  373.  
  374. /*
  375.  *  plane state
  376.  */
  377. extern Matrix ptw;            /* my ptw matrix */
  378. extern float (*my_ptw)[4];        /* pointer to my matrix    */
  379. extern int sidewinders, rockets;    /* number of armaments        */
  380. extern float rudder, elevator, rollers;    /* control settings        */
  381. extern float vx, vy, vz;        /* plane velocity */
  382. extern int twist, elevation, azimuth;    /* plane orientation        */
  383. extern int roll_speed;            /* roll, elevation, azimuth speeds */
  384. extern int elevation_speed;        /* in 10'ths degrees per tick    */
  385. extern int azimuth_speed;
  386. extern int flaps, spoilers;        /* flap and spoiler settings    */
  387. extern float lift;            /* lift acceleration        */
  388. extern int airspeed, last_airspeed;
  389. extern int climbspeed, last_climbspeed;
  390. extern short g_limit;            /* TRUE if wing g-limit is hit    */
  391. extern short wing_stall;        /* TRUE if wing is stalling    */
  392. extern short on_ground;            /* TRUE if plane is on ground    */
  393. extern short wheels;            /* TRUE if the wheels are down    */
  394. extern short wheels_retracting;        /* used only            */
  395. extern short landing_gear_stuck;    /* >= 0 if the gear is stuck    */
  396. extern int fuel;            /* fuel (0 - 12800)        */
  397. extern int thrust;            /* thrust (0 - 100)        */
  398. extern int throttle;            /* throttle (0 - 100)        */
  399. extern int max_throttle;        /* upper limit on engines    */
  400. extern int min_throttle;        /* lower limit on engines    */
  401. extern float last_px, last_py, last_pz;    /* last plane position        */
  402. extern float max_cl, min_cl;        /* max and min coefficient of lift */
  403. extern float tilt_factor;        /* wing angle tilt due to flaps    */
  404. extern float Splf, Spdf;        /* spoiler factors on lift and drag */
  405. extern float mach;            /* mach #, crest critical #, ratio */
  406. extern float Cdp;            /* coefficient of parasitic drag */
  407.  
  408. /*
  409.  *  autopilot state
  410.  */
  411. extern short autopilot_on;        /* TRUE in autopilot mode */
  412. extern int target_twist;        /* target twist for autopilot */
  413. extern int target_speed;        /* target speed for autopilot */
  414. extern int target_climb;        /* target climb for autopilot */
  415.  
  416.  
  417. /*
  418.  *  missile status
  419.  */
  420. extern long missile_target;        /* plane my missile is after */
  421. extern float missile_vx,        /* missile velocity */
  422.          missile_vy,
  423.          missile_vz;
  424. #define MT_MAX 30
  425.  
  426. /*
  427.  *  wingman history
  428.  */
  429. extern int wm_twist[10];
  430. extern int wm_elevation[10];
  431. extern int wm_azimuth[10];
  432. extern float wm_x[10], wm_y[10], wm_z[10];
  433. extern int wmpos;
  434. extern int wmspos;
  435. extern int wmfollow;
  436.  
  437. /*
  438.  *  view state
  439.  */
  440. extern short view_switch;
  441. #define PLANE_VIEW 1
  442. #define TOWER_VIEW 2
  443. extern int wingman_view;
  444. extern int missile_view;
  445. extern int fov;                /* field of view */
  446. extern int plane_fov, tower_fov;    /* plane, tower field of view */
  447. extern float ar;            /* aspect rationo */
  448. extern long dist_for_lines;        /* distance to draw building lines */
  449. extern int view_angle;            /* rotation of pilot's head */
  450. extern int fogit;
  451. extern int texit;
  452. extern float eye_x, eye_y, eye_z;    /* eye position */
  453. extern float current_eye[4];        /* current eye position */
  454.  
  455. #define TOWER_X -1950.0
  456. #define TOWER_Y   400.0
  457. #define TOWER_Z -3150.0
  458. extern float frustum[4][4];
  459. extern float clip_planes[4][4];
  460.  
  461.  
  462. extern int fog_d;
  463.  
  464. /*
  465.  *  airshow input/output file control
  466.  */
  467. extern char *infile, *outfile;
  468. extern FILE *inf, *outf;
  469. extern int read_pause;
  470. extern int read_reset;
  471. extern int read_backwards;
  472. extern float read_speed;
  473.  
  474.  
  475. #define MIN(a, b) ((a < b) ? a : b)
  476. #define MAX(a, b) ((a > b) ? a : b)
  477.  
  478. #include "proto.h"
  479.  
  480. #endif /* __FLIGHT_H__ */
  481.